<template>
	<view id="page">
		<nav-bar :navH="navH" :isTabar="false" :isHome="false" :pageName="title"></nav-bar>
		<block v-if="hasRes">
			<view class='list'>
				<block v-for="(it, k2) in lists" :key="k2">
					<view class="flex-i item" @click="goDetail(it.id)">
						<view class="pic">
							<image :src="it.imgs" mode='widthFix' lazy-load="true" @error="imgError(k2)"></image>
						</view>
						<text class="title">{{it.title}}</text>
						<image src='../../static/9.png' mode="widthFix" lazy-load="true" class="isvideo" v-if="it.is_video == 1"></image>
					</view>
				</block>
			</view>
		</block>
		<view class="nocont" v-else>暂无内容</view>
		<view class="nomore" v-if="isLoad"><image src='../../static/nomore_img.png' mode="widthFix"></image><text>没有更多了~</text></view>
		<scope-box :isLogin="isLogin" @isShow="isShow"></scope-box>
	</view>
</template>

<script>
	import app from '../../common/index.js'
	export default {
		data() {
			return {
				title: '我的案例',
				navH: null,
				userInfo: {},
				isLogin: false,
				doctId: '',  // 医生ID
				hasRes: true,
				isLoad: false,
				page: 1,
				size: 10,
				lists: [],
			}
		},
		onLoad(options) {
			this.navH = this.$store.state.navHeight;
			this.doctId = options.id;
			// 获取本地用户信息
			this.userInfo = uni.getStorageSync('uinfo');
			if(!this.userInfo.id) {
				this.isLogin = true;
			}
			this.getCase();
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1;
			this.lists = [];
			// 获取本地用户信息
			this.userInfo = uni.getStorageSync('uinfo');
			this.getCase();
			uni.stopPullDownRefresh();
		},
		/**
		 * @des 上划加载
		 */
		onReachBottom() {
			if(!this.isLoad) {
				this.page = this.page + 1;
				this.getCase();
			}
		},
		// 分享转发
		onShareAppMessage() {
			return {
				title: '名医案例',
				path: 'pages/case/index?id='+ this.doctId,
			}
		},
		methods: {
			/**
			 * @des 登录提示框
			 */
			isShow() {
				this.isLogin = false;
			},
			/**
			 * @des 获取案例列表
			 */
			getCase() {
				app.request({
					url: 'entry/wxapp/DoctorCaseList',
					data: {
						doctor_id: this.doctId,
						user_id: this.userInfo.id,
					}
				}, (ret) => {
					console.log(ret);
					let d = ret.data, tmpData = this.lists, len = d.data.length;
					if (d.total > 0) {
						this.hasRes = true;
						this.lists = tmpData.concat(d.data);
						this.isLoad = len < this.size ? true : false;
					} else {
						this.hasRes = false;
					}
				})
			},
			/**
			 * @des 打开案例详情
			 */
			goDetail(id) {
				uni.navigateTo({
					url: '../casedetail/index?id='+ id,
				})
			},
			/**
			 * @des 处理错误图片
			 */
			imgError(i) {
				let tmpLists = this.lists;
				tmpLists[i].imgs = '../../static/default.jpg';
				this.lists = tmpLists;
			}
		}
	}
</script>

<style>
	/* 图文列表 */
	.flex-i {margin: 0 10upx;}
	.list {margin: 0 -10upx; column-gap: 5upx;}
	.list .item {margin-bottom: 20upx; box-shadow: 0 6upx 6upx #ddd; border-radius: 10upx; background-color: #fff; break-inside: avoid;}
	.list .item {position: relative; box-shadow: 0 6upx 6upx #ddd; border-radius: 10upx; background-color: #fff;}
	.list .item .pic {height: 480upx; overflow: hidden;}
	.list .item .title {padding-bottom: 20upx;}
	.list .item .isvideo {position: absolute; top: 26upx; right: 26upx; width: 60upx; height: 60upx; z-index: 113;}
</style>
